package org.gp953.quartz.job;

import org.gp953.order.service.IAdoptOrderService;
import org.gp953.order.service.IProductOrderService;
import org.gp953.quartz.consts.QuartzConsts;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

public class MainJob implements Job {
    @Autowired
    private IAdoptOrderService adoptOrderService;
    @Autowired
    private IProductOrderService productOrderService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDetail jobDetail = jobExecutionContext.getJobDetail();
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        Map<String, Object> params = (Map<String, Object>) jobDataMap.get("params");
        String type = (String) params.get("type");
        switch (type) {
            case QuartzConsts.PAY_OVER_TIME_ADOPT_ORDER:
                Long adoptOrderId = (Long) params.get("orderId");
                adoptOrderService.deleteQuartzJobByOrderId(adoptOrderId);
                break;
            case QuartzConsts.PAY_OVER_TIME_PRODUCT_ORDER:
                Long productOrderId = (Long) params.get("orderId");
                productOrderService.deleteQuartzJobByOrderId(productOrderId);
                break;

            default:
                break;
        }
    }
}
